#include <cstdio>

int main( )
{
    int t, i, dd, n, a[ 10000 ], sum, j, minsum, cas = 1, tt;
    bool flag;
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%d%d", &dd, &n);
        for ( i = 0; i < n; i++ )
            scanf("%d", &a[ i ]);
        sum = 0;
        minsum = 0x7fffffff;
        for ( i = 0; i < n; i++ )
        {
            sum += a[ i ];
            tt = 0;
            flag = true;
            for ( j = i + 1; j < n; j++ )
            {
                tt += a[ j ];
                if ( tt == sum )
                    tt = 0;
                if ( tt > sum )
                {
                    flag = false;
                    break;
                }
                if ( j == n - 1 && tt != 0 )
                    flag = false;
            }
            if ( flag && minsum > sum )
                minsum = sum;
        }
        printf("%d %d\n", cas++, minsum);
    }
    return 0;
}